
from ability.models import Course, GovCourse
from django.conf import settings
from ability.format import FormatTransField
from rest_framework import serializers


class SatCourseListSerializer(serializers.ModelSerializer):
    avatar_url = serializers.SerializerMethodField()
    course_id = serializers.CharField(source='id')
    create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
    course_type = FormatTransField(transname='course_type')
    score = serializers.SerializerMethodField()
    comment = serializers.SerializerMethodField()
    
    class Meta:
        model = Course
        fields = ['course_id', 'course_name', 'create_time', 'status', 'course_type', 'avatar_url', 'describe']
    
    def get_avatar_url(self, obj):
        return settings.MEDIA_HOST + obj.avatar.location.url
			
class GovCourseListSerializer(serializers.ModelSerializer):
		avatar_url = serializers.SerializerMethodField()
		create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
		course_name = serializers.CharField(source='course.course_name')
		
		class Meta:
				model = GovCourse
				fields = ['course_id', 'course_name', 'create_time', 'avatar_url']
		
		def get_avatar_url(self, obj):
				return settings.MEDIA_HOST + obj.course.avatar.location.url
